<template>
  <div style="padding: 0 15px;">
      <van-nav-bar
          left-arrow
          title="设置"
          @click-left="onClickLeft"
      />
    <van-cell-group align="left" style="margin-top: 20px">
      <van-cell @click="updatePhone" style="height: 60px;font-size: 20px;border-bottom: 1px solid rgba(0,0,0,0.2);border-top: 1px solid rgba(0,0,0,0.2);"
                title="更改手机号码" is-link center>
        <template #right-icon>
          <van-icon name="arrow"/>
        </template>
      </van-cell>
      <van-cell @click="updatePassword" style="height: 60px;font-size: 20px;border-bottom: 1px solid rgba(0,0,0,0.2);"
                title="修改密码" is-link center>
        <template #right-icon>
          <van-icon name="arrow"/>
        </template>
      </van-cell>
    </van-cell-group>
    <el-button @click="loginOut" style="width: 100%;height: 50px;margin: 10px auto;font-size: 20px;color: #2984f8">退出登录</el-button>

  </div>
</template>

<script>
export default {
  name: "SettingsView",
  data() {
    return {}
  },
  created() {
    const token = JSON.parse(localStorage.getItem("token"));
    if (!token) {
      this.$message.error('请先登录');
      setTimeout(() => {
        this.$router.push({name: 'login'});
      });
    }
    // 设置全局默认请求头
    this.axios.defaults.headers.common['token'] = token;
  },
  methods: {
    onClickLeft() {
      this.$router.push({name: 'my'})
    },
    updatePhone() {
      this.$router.push({name: 'updatePhone'})
    },
    updatePassword() {
      this.$router.push({name: 'updatePassword2'})
    },
    loginOut() {
      localStorage.removeItem("token")
      this.$message.success('退出成功')
      this.$router.push({name: 'login'})
    }
  },
}
</script>

<style scoped>

</style>